/*
 * @Author: liyuxiao 1273661256@qq.com
 * @Date: 2022-02-21 10:25:28
 * @LastEditors: liyuxiao 1273661256@qq.com
 * @LastEditTime: 2022-08-10 09:14:28
 * @FilePath: /cscec-pms-admin/src/api/safetySupervision/index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from '@/utils/request'
import { notification } from 'ant-design-vue'
import { safetyApiUrl, commonApiUrl, appApiUrl } from '@/api/config.js'

const errorTips = '请求失败，请稍后重试！'
const prefix = safetyApiUrl
const commonPrefix = commonApiUrl
const appPrefix = appApiUrl

export async function handleRequest(options, config = {},timeout=1000 * 60 * 5) {
  const p = request({
    timeout: timeout,
    ...options,
    url: `${ config.useApp ? appPrefix : config.useCommon ? commonPrefix : prefix}${options.url}` // useCommon：是否使用通用服务
  })
  try {
    const res = await p
    if ((res.code !== 200 && res.data && res.data.code !== 200) || (res.status === 200 && !res.data)) {
      // notification.error({
      //   message: '提示',
      //   description: (res.data && res.data.message) || errorTips
      // })
      throw new Error((res.data && res.data.message) || errorTips)
    } else {
      return [null, res]
    }
  } catch (e) {
    return [e, null]
  }
}
